package leetcode.N801_N900;

/**
 * @author xiwai [hww282306@alibaba-inc.com]
 * @version 1.0
 * @date 2020/12/10 11:00 上午
 */
public class N860 {

    public boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;
        for (int bill : bills) {
            if (bill == 5) {
                five++;
            } else if (bill == 10 && five > 0) {
                five--;
                ten++;
            } else if (bill == 20 && five > 0 && ten > 0) {
                five--;
                ten--;
            } else if (bill == 20 && five > 2) {
                five -= 3;
            } else {
                return false;
            }
        }
        return true;
    }

}
